<template>
<div>
    <van-nav-bar
      title='搜索结果'
      left-text="返回"
      left-arrow
      @click-left="onClickLeft()"
    />
  <van-card v-for="(s,index) in getbook" 
  :key="index"
  :title="getbook[index].name"
  :desc="getbook[index].author"
  :price="getbook[index].price"
  :thumb="'/'+getbook[index].img"
  @click="change1(getbook[index].id,index)"
> 

<template #tags>
    <van-tag plain type="danger">{{categories[getbook[index].category].name}}</van-tag>
  </template>
  </van-card>
</div>
</template>
<script>
import axios from "axios"
import network from "../network"
export default {
    data:function()
    {
        return{
            name:this.$route.params.value,
            getbook:[],
            categories: [],
        }
    },
    created: function () {
    
    let self = this;
    this.name=this.$route.params.value;
    network.get_book_by_name(self.name).then(function (response){
      self.getbook = response.data;
    });
     network.get_category().then(function (response) {
      self.categories = response.data;
    });
    },
    methods: {
     change1(id,index)
      {
       this.$router.push(`/newpage/${id}/${this.getbook[index].category}`);
      
     },
    onClickLeft() {
      this.$router.go(-1);
    }
    }
}
</script>